<template>
	<view class="container">
		<view class="card-view" v-for="(item,index) in goodsList" :key="index">
			<uni-card class="card" @click="navTo(item)" :padding="0" :margin="0" :cover="item.goods_img_url">
			</uni-card>
			<view class="txt_con">
				<text>名称:{{item.goods_name}}</text>
				<text>描述:{{item.detail_page}}</text>
				<text>价格:{{item.price}}元</text>
				<text>库存:{{item.stocks}}</text>
			</view>
			<view>
				<button plain @click='navTo(item)'>购买</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goodsList: [{
					detail_page: "",
					goods_img_url: "",
					goods_name: "",
					id: "",
					price: "",
					stocks: "",
				}],
			};
		},
		onLoad() {
			let that = this;
			uni.request({
				url: "http://localhost:8090/goods/getGoodsList",
				method: "GET",
				success(res) {
					that.goodsList = res.data.data;
				}
			})
		},
		methods: {
			navTo(item) {
				uni.navigateTo({
					url: "/pages/other/order",
					success: (res) => {
						res.eventChannel.emit("navToOrder", item)
					}
				})
			}
		},
	};
</script>

<style lang="scss" scoped>
	.container {
		display: flex;
		flex-direction: row;
		align-content: space-around;
		flex-wrap: wrap;
	}

	.card-view {
		width: 49%;

	}
	.txt_con{
		display: flex;
		flex-direction: column;
	}
</style>